// import { resolve } from 'path';
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueSetupExtend from 'vite-plugin-vue-setup-extend';
// import {ElementPlusResolver} from 'unplugin-vue-components/resolvers';
// import AutoImport from 'unplugin-auto-import/vite';
// import Components from 'unplugin-vue-components/vite';
import {viteMockServe} from 'vite-plugin-mock';
import importToCDN from 'vite-plugin-cdn-import';

export default defineConfig(
  {
    build: {
      //打包移除console 和 debugger
      minify: 'terser',
      terserOptions:{
        compress: {
          drop_console: true,
          drop_debugger: true
        }
      },
      outDir: 'dist', // 打包输出文件夹
      assetsDir: 'assets', // 静态资源目录
      manifest: false,
      rollupOptions: {
        output: {
          chunkFileNames: `js/[name]-[hash].js`,
          entryFileNames: `js/[name]-[hash].js`,
          assetFileNames: `assets/[ext]/[name]-[hash].[ext]`
        }
      }
    },
    plugins: [
      // AutoImport({
      //   resolvers:[ElementPlusResolver()]
      // }),
      // Components({
      //   resolvers:[ElementPlusResolver()]
      // }),
      importToCDN({
        modules:[
          {
            name: "vue",
            var: "Vue",
            path: "https://unpkg.com/vue@next"
          },
          {
            name: "element-plus",
            var: "ElementPlus",
            path: "https://unpkg.com/element-plus",
            css: "https://unpkg.com/element-plus/dist/index.css"
          }
        ]
      }),
      viteMockServe({
        mockPath: 'mock'
      }),
      vue(),
      VueSetupExtend()
    ],
    resolve: {
      alias: {
        '@': '/src/'
      }
    },
    server: {
      proxy: {
        '^/api': {
          target: 'https://v3pro.houjiemeishi.com/',
          changeOrigin: true,
          ws: true,
          rewrite: (path)=> path.replace(/^\/api/,'')
        }
      }
    }
  }
)